package ljl.codetop300;

/**
 * 输入：matrix = [
 * [1,3,5,7],
 * [10,11,16,20],
 * [23,30,34,60]], target = 3
 * 输出：true
 * 示例 2：
 *
 *
 * 输入：matrix = [
 * [1,3,5,7],
 * [10,11,16,20],
 * [23,30,34,60]], target = 13
 * 输出：false
 *
 * 和那个简单题怎么感觉一样
 */
public class _74_search_matrix {

  static class test {

    public boolean searchMatrix(int[][] matrix, int target) {
      int m = matrix.length;
      int n = matrix[0].length;
      int i = 0, j = n - 1;
      while (i < m && j > -1) {
        if (matrix[i][j] == target) return true;
        if (matrix[i][j] > target) j--;
        else i++;
      }
      return false;
    }
  }
}
